package com.hzy.orderSystem.controller;

import com.hzy.orderSystem.utils.CommonResult;
import com.hzy.orderSystem.utils.FileUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author 小宝
 * @create 2021/4/21 10:25
 */

@RestController
@RequestMapping("/file")
public class FileController {

    @PostMapping("/upload")
    public CommonResult upload(@RequestParam("file") MultipartFile file) throws IOException {
        if(file.isEmpty())
            return new CommonResult(40000, "上传失败，请重新选择文件");
        String url = FileUtil.uploadFile(file);
        return new CommonResult(20000, "上传成功", url);
    }
}
